package com.yidaba.test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class test {
	public static void main(String[] args){
		test t = new test();
//		t.exec("ipconfig");
		t.exec("e:\\test.bat");
		
//		byte[] buffer = new byte[4096];
//		Runtime r = Runtime.getRuntime();
//		Process p = null;
//		try{
////        p = r.exec("/bin/sh /root/test.sh");
//			p = r.exec("e:\\test.bat");
//			OutputStream ops = p.getOutputStream();
//			BufferedOutputStream bops = new BufferedOutputStream(ops);
//			PrintStream ps = new PrintStream(ops);
//			ps.println("echo ddddddddd");
//			InputStream is = p.getInputStream();
//			BufferedInputStream sis = new BufferedInputStream(is);
//			sis.read(buffer, 0, 4096);
//			String str = new String(buffer);
//			System.out.println(str);
//			int exitVal = p.exitValue();
//            System.out.println("Process exitValue: " + exitVal);
//            
////			FileOutputStream file = new FileOutputStream(new File("e:\\test2.txt"));  
////        PrintStream ps2 = System.out;
//		} catch (Exception e) {
//			System.out.println("Error executing notepad.");
//		}
	}
	
	public void exec(String cmd){
	      String command=cmd;
	      Runtime r=Runtime.getRuntime();   
	      Process p;
		try {
			p = r.exec(command);
			BufferedReader br=new BufferedReader(new InputStreamReader(p.getInputStream()));   
			StringBuffer sb=new StringBuffer();   
			String inline;   
			while(null!=(inline=br.readLine())){   
				sb.append(inline).append("\n");   
			}   
			System.out.println(sb.toString());   
		} catch (IOException e) {
			e.printStackTrace();
		}   
	}
}
